/*
 * @lc app=leetcode.cn id=3 lang=golang
 *
 * [3] 无重复字符的最长子串
 */
package main

import (
	"strings"
)

//zwnigfunjwz
// @lc code=start
func lengthOfLongestSubstring(s string) int {
	if len(s) == 0 {
		return 0
	}
	max := 0
	p := 0
	for i := 1; i < len(s); i++ {
		//aaaaaa
		if n := strings.IndexByte(s[p:i], s[i]); n != -1 {

			if i-p > max {
				max = i - p
			}
			p = p + n + 1
		}
	}
	if len(s)-p > max {
		max = len(s) - p
	}
	return max
}

// @lc code=end
